<template>
  <div class="reward-table">
    <div v-if="originData && originData.items.length > 0">
      <el-table
        :data="originData.items"
        :row-class-name="tableRowClassName"
        size="mini"
        header-row-class-name="table-header"
      >
        <!-- <el-table-column label="序号" width="50" align="center">
        <template slot-scope="scope">
          {{ scope.$index + 1 }}
        </template>
      </el-table-column> -->
        <el-table-column
          label="赞赏人"
          align="center">
          <template slot-scope="scope">
            <div class="name-item">
              <img :src="scope.row.wxIcon" class="avatar" alt="">
              <el-tooltip style="max-width: 90%;" class="item" placement="top" effect="dark">
                <div slot="content" style="max-width: 200px;">
                  <div v-if="scope.row.wxName && scope.row.wxName.indexOf('emoji') >= 0" class="reward-emoji-container" v-html="scope.row.wxName"/>
                  <div v-else>{{ scope.row.wxName }}</div>
                </div>
                <div class="content">
                  <div v-if="scope.row.wxName && scope.row.wxName.indexOf('emoji') >= 0" class="name" v-html="scope.row.wxName"/>
                  <div v-else class="name">{{ scope.row.wxName }}</div>
                </div>
              </el-tooltip>
            </div>
          </template>
        </el-table-column>
        <el-table-column
          label="总赞赏金额"
          align="center">
          <template slot-scope="scope">
            <div>{{ scope.row.price | moneyFilter }}</div>
          </template>
        </el-table-column>
        <el-table-column
          label="赞赏时间"
          align="center">
          <template slot-scope="scope">
            <div v-if="scope.row.dateTime">{{ scope.row.dateTime | format('YYYY-MM-DD HH:mm:ss') }}</div>
            <div v-else>--</div>
          </template>
        </el-table-column>
      </el-table>
      <div style="display: flex;justify-content:center;">
        <el-pagination
          :total="originData.total"
          :current-page="originData.page"
          :page-size="originData.perPage"
          :layout="isMobile?'prev, next':'prev, pager, next'"
          @current-change="handleCurrentChange"/>
      </div>
    </div>
    <div v-else class="empty-container">
      <img :src="emptyImg" alt="">
      <div class="empty-text">暂无数据</div>
    </div>
  </div>
</template>

<script>
import { format } from '@/filters/date';
import { moneyFilter } from '@/filters/number';
import emptyImg from '@/assets/empty-table-data.png';
export default {
  filters: { format, moneyFilter },
  props: {
    originData: {
      type: Object,
      default: () => {
        return {};
      }
    },
    isMobile: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      emptyImg
    };
  },
  methods: {
    tableRowClassName({ row, rowIndex }) {
      return rowIndex % 2 ? 'double-row' : 'single-row';
    },
    handleCurrentChange(page) {
      this.$emit('getReward', page);
    }
  }
};
</script>
<style lang="scss" scoped>
.name-item {
  display: flex;
  padding: 2px 0;
  align-items: center;
  .avatar {
    border-radius: 100%;
    object-fit: cover;
    width: 25px;
    height: 25px;
    margin-right: 10px;
  }
  .name {
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
    &::v-deep {
      @import '@/styles/emoji.scss';
      .emoji {
        position: relative;
        top: 4px;
      }
    }
  }
}
.empty-container {
  margin: 0 auto;
  img {
    width: 120px;
    margin: 0 auto;
    display: block;
  }
  .empty-text {
    color: #666;
    font-size: 15px;
    text-align: center;
  }
}
.reward-table {
  ::v-deep .el-table {
    .table-header {
      .is-leaf {
        border-left: 1px solid #fff;;
        border-right: none;
        border-bottom: 1px solid transparent;
        &:first-child{
          border-left: none;
        }
      }
    }
    .table-header > th {
      background: #85A2FF;
      font-size:14px;
      padding: 2px 0;
      &> .cell {
        color: white;
      }
    }
    .double-row {
      background: #CED5F6;
      &:hover {
        td {
          background: #CED5F6;
        }
      }
    }
    .single-row {
      background: #EAEDFF;
      padding: 0;
      &:hover {
        td {
          background: #EAEDFF;
        }
      }
    }
    .double-row, .single-row  {
      td {
        font-size: 14px;
        padding: 2px 0;
        line-height: 1.2;
        border-left: 1px solid #fff;
        border-right: none;
        border-bottom: 1px solid transparent;
        &:first-child{
          border-left: none;
        }
      }
    }
  }
}

::v-deep {
  .reward-emoji-container {
    line-height: 20px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
  }
}
</style>
